using System;
using System.Collections.Generic;
using System.Text;
using System.Web.Script.Serialization;
using System.Configuration;

namespace Channelvn.Storage
{
    public class Utils
    {
        public static ChannelvnDirInfo ConvertToDirectorObj(string jsonString)
        {
            try
            {
                JavaScriptSerializer js = new JavaScriptSerializer();
                //List<ChannelvnDirInfo> dir = js.Deserialize<List<ChannelvnDirInfo>>(jsonString);
                ChannelvnDirInfo dir = js.Deserialize<ChannelvnDirInfo>(jsonString);
                return dir;
            }
            catch (Exception ex)
            {
                //Console.WriteLine("Error..... " + ex.StackTrace);
                throw ex;
            }
        }

        public static ChannelvnFileInfo ConvertToFileObj(string jsonString)
        {
            try
            {
                JavaScriptSerializer js = new JavaScriptSerializer();
                ChannelvnFileInfo fileInfo = js.Deserialize<ChannelvnFileInfo>(jsonString);
                return fileInfo;
            }
            catch (Exception ex)
            {
                //Console.WriteLine("Error..... " + ex.StackTrace);
                throw ex;
            }
        }

        public static string GetFolder(string folderName, string prefix) {
            try
            {
                //string prefix = ConfigurationManager.AppSettings["Prefix"];

                if (folderName.StartsWith(prefix))
                    return folderName.Substring(prefix.Length);
                else
                    return folderName;
            }
            catch (Exception ex) {
                throw ex;
            }
        }
    }
}
